package com.butang.controller;

import com.butang.pojo.Emp;
import com.butang.pojo.Result;
import com.butang.service.EmpServiceImpl;
import com.butang.utils.JwtUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * ClassName: LoginController
 * Package: com.butang.controller
 * Description:
 *
 * @Author BuTang
 * @Create 2023/7/17 18:26
 * @Version 1.0
 */
@Slf4j
@RestController
public class LoginController {
@Autowired
private EmpServiceImpl empService;
    @PostMapping("/login")
    public Result login(@RequestBody Emp emp) {
        Emp login = empService.login(emp);
        if (login != null) {
            Map map = new HashMap();
            map.put("username",login.getUsername());
            map.put("password",login.getPassword());
            //map.put(login.getUsername(),login.getPassword());
            String s = JwtUtils.generateJwt(map);
            return Result.success(s ) ;
        }
        return Result.error("NOT_LOGIN");
    }
}
